﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using XYAC.Framework.MonitorTireMaterialManual.Extensions;
using XYAC.Framework.MonitorTireMaterialManual.ViewModels;
using XYAC.Framework.MonitorTireMaterialManual.Views;

namespace XYAC.Framework.MonitorTireMaterialManual.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public int HistorySelectedIndex { get; private set; }

        public MainWindow(IOptionsMonitor<AppConfig> options, ILogger<MainWindow> logger, 
            MainWindowViewModel viewmodel, 
            GbQualityDataUploadView uploadView, 
            SystemConfigView systemConfigView,
            QualityDataHistoryView qualityDataHistoryView
            /*SemiSteelTreadScanView semiSteelTreadScanView*/)
        {

            this.DataContext = viewmodel;

            InitializeComponent();

            (this.MainTab.Items[0] as TabItem).Content = uploadView;
            (this.MainTab.Items[1] as TabItem).Content = qualityDataHistoryView;
            (this.MainTab.Items[2] as TabItem).Content = systemConfigView;
            //(this.MainTab.Items[3] as TabItem).Content = semiSteelTreadScanView;

            var workingArea = SystemParameters.WorkArea;
            this.Width = workingArea.Width;
            this.Height = workingArea.Height;

            this.Closing += MainWindow_Closing;

        }

        private void MainWindow_Closing(object? sender, CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }


        private void MainTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((this.MainTab.SelectedItem as TabItem).Content is QualityDataHistoryView view && this.HistorySelectedIndex != this.MainTab.SelectedIndex && view.DataContext is QualityDataHistoryViewModel vm)
            {
                vm.QueryLocalDataHistory();
            }
            this.HistorySelectedIndex = this.MainTab.SelectedIndex;
        }
    }
}